var shopOrderCode = '';
var page = 1;
function doDetail() {
    $.ajax({
        url:'/crm/refundLogC/getById.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            id:$('#idBox').html(),
        },
        type:'post',
        success:function (data) {
            if(data.code==1){
                var editData = data.datas;
                $('#code').val(editData.code);
                shopOrderCode = editData.code;
                $('#referCode').val(editData.referCode);
                $('#goodsOrderCode').val(editData.goodsOrderCode);
                $('#userName').val(editData.userName);
                $('#realName').val(editData.realName);
                $('#shopName').val(editData.shopName);
                $('#goodsName').val(editData.goodsName);
                $('#specificationName').val(editData.specificationName);
                $('#goodsNum').val(editData.goodsNum);
                $('#payMoney').val(editData.payMoney);
                $('#refundMoney').val(editData.refundMoney);
                $('#num').val(editData.num);
                $('#refundState').val(editData.refundState);
                $('#refundType').val(editData.refundType);
                $('#refundReason').val(editData.refundReason);
                $('#createTime').val(editData.createTime);
                $('#handleTime').val(editData.handleTime);
                $('#handleUser').val(editData.handleUser);
                for(var i=0;i<editData.picture.split(',').length-1;i++){
                    $('#picture').append($('<img style="width: 60px;height: 60px;" src="'+editData.picture.split(',')[i]+'"/>'))
                }
                if(editData.refundStateValue==1){
                    $('#tongyi,#bohui').show();
                }
            }
        }
    })
}

doDetail();

//同意发货
var handleValue =''
$('#tongyi,#bohui').click(function () {
    handleValue =$(this).attr('value');
})
$('#save').click(function () {
    var refundMoney1= $('#refundMoney1').val();
    var num1=$('#num1').val();
    edit(refundMoney1,num1);

})
$('#bohui').click(function () {
    var refundMoney1='';
    var num1='';
    edit(refundMoney1,num1);
})

function edit(refundMoney1,num1) {
    $.ajax({
        url:'/crm/refundLogC/edit.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            id:$('#idBox').html(),
            handleValue:handleValue,
            refundMoney:refundMoney1,
            num:num1,
        },
        type:'post',
        success:function (data) {
            if(data.code==0){
                alert(data.msg)
                return;
            }
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==1){
                if(handleValue==3){
                    alert('退款成功');
                }else {
                    alert('退款已拒绝');
                }
                $('#ckModal1').removeClass('fade in');
                $('#ckModal1').addClass('fade');
                $('#ckModal1').attr('aria-hidden',true);
                $('#ckModal1').css('display','none');
                $('.modal-backdrop').css('display','none');
                $('#ckModal1 input').val('');
                doDetail();
            }
        }
    })
}
